
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_SIKKERHED_SESSION]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[EBAS_SIKKERHED_SESSION]
GO

CREATE TABLE [dbo].[EBAS_SIKKERHED_SESSION] (
	[GUID] [uniqueidentifier] ROWGUIDCOL NOT NULL ,
	[SIKKERHED_BRUGER_GUID] [uniqueidentifier] NOT NULL ,
	[SIKKERHED_OBJEKT_TYPE_GUID] [uniqueidentifier] NOT NULL ,
	[SLUT_DATO] [datetime] NOT NULL ,
	[OPRETTET_DATO] [datetime] NOT NULL ,
	[DEAKTIVERET] [bit] NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_SIKKERHED_SESSION] WITH NOCHECK ADD 
	CONSTRAINT [DF_EBAS_SIKKERHED_SESSION_DEAKTIVERET] DEFAULT (0) FOR [DEAKTIVERET],
	CONSTRAINT [DF_EBAS_SIKKERHED_SESSION_OPRETTET_DATO] DEFAULT (getDate()) FOR [OPRETTET_DATO],
	CONSTRAINT [DF_EBAS_SIKKERHED_SESSION_SLUT_DATO] DEFAULT (DATEADD(minute, 15, getDate())) FOR [SLUT_DATO],
	CONSTRAINT [PK_EBAS_SIKKERHED_SESSION] PRIMARY KEY  CLUSTERED 
	(
		[GUID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[EBAS_SIKKERHED_SESSION] ADD 
	CONSTRAINT [FK_EBAS_SIKKERHED_SESSION_EBAS_SIKKERHED_BRUGER] FOREIGN KEY 
	(
		[SIKKERHED_BRUGER_GUID]
	) REFERENCES [dbo].[EBAS_SIKKERHED_BRUGER] (
		[GUID]
	)
GO
